home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-06-28 | 1.7 KB | 68 lines | [TEXT/CWIE] |
- // TreeNode.h
-
- #ifndef TreeNode_h
- #define TreeNode_h
-
- #ifndef Assert_h
- #include "Assert.h"
- #endif
-
- class TreeNode
- {
- friend class Tree;
-
- private:
- Tree *tree;
- TreeNode *parent;
- TreeNode *left;
- TreeNode *right;
-
- // not implemented:
- TreeNode( const TreeNode& );
- void operator=( const TreeNode& );
-
- TreeNode*& LinkFromAbove();
-
- TreeNode *NextNode() const;
- TreeNode *PreviousNode() const;
- TreeNode *SiblingNode() const;
-
- public:
- TreeNode();
- ~TreeNode();
-
- bool Owned() const { return tree != 0; }
- Tree& Owner() const { Assert( tree != 0 ); return *tree; }
-
- const TreeNode *Parent() const { return parent; }
- const TreeNode *Left() const { return left; }
- const TreeNode *Right() const { return right; }
- const TreeNode *Next() const { return NextNode(); }
- const TreeNode *Previous() const { return PreviousNode(); }
- const TreeNode *Sibling() const { return SiblingNode(); }
-
- TreeNode *Parent() { return parent; }
- TreeNode *Left() { return left; }
- TreeNode *Right() { return right; }
- TreeNode *Next() { return NextNode(); }
- TreeNode *Previous() { return PreviousNode(); }
- TreeNode *Sibling() { return SiblingNode(); }
-
- bool IsRoot() const { return parent == 0; }
- bool IsLeftChild() const { return parent != 0 && parent->left == this; }
- bool IsRightChild() const { return parent != 0 && parent->right == this; }
-
- bool HasLeftChild() const { return left != 0; }
- bool HasRightChild() const { return right != 0; }
- bool IsLeaf() const { return left == 0 && right == 0; }
-
- void SwapWith( TreeNode& );
- void RotateUp();
-
- uint32 Depth() const;
-
- bool Valid() const; // Should always be true
- };
-
- #endif
-